package com.example.demo.service;

import com.easy.query.api4j.client.EasyQuery;
import com.easy.query.solon.annotation.Db;
import com.example.demo.entity.User;
import org.noear.solon.annotation.Component;

import java.util.List;

/**
 * userService
 */
@Component
public class MyUserService {

    @Db("db1")
    private EasyQuery easyQuery;

    /**
     * 获取user list
     */
    public List<User> fetchUsers(List<Long> userIds) {
        return easyQuery.queryable(User.class)
                .where(w -> w.in(User::getId, userIds))
                .toList();
    }

    /**
     * 获取user
     */
    public User fetchUser(Long userId) {
        return easyQuery.queryable(User.class)
                .where(w -> w.eq(User::getId, userId))
                .firstOrNull();
    }
}
